#include <iostream>
#include <iomanip>
using namespace std;

void square(int n, char fill = '*') {
    cout.fill(fill);
    for (int i = 0; i<n; ++i)
        cout << setw(n) << "" << endl;
}

void diamond(int n, char fill = '*') {
    n = (n % 2) ? n: n+1;
    int i = 1, step = 1;
    while (1) {
        if ( i == (n + 1)/2 ) step = -1;
        int stars = 2*i -1; 
        int spaces = (n - stars)/2;
        cout.fill(' ');
        cout << setw(spaces) << "";
        cout.fill(fill);
        cout << setw(stars) << "";
        cout.fill(' ');
        cout << setw(spaces) << "" << endl;
        if ((i += step) == 0) break;
    } 
}

void triangle(int n, char fill = '*') {
    n = (n % 2) ? n: n+1;
    int i = 1, step = 1;
    while (1) {
        int stars = 2*i -1; 
        int spaces = (n - stars)/2;
        cout.fill(' ');
        cout << setw(spaces) << "";
        cout.fill(fill);
        cout << setw(stars) << "";
        cout.fill(' ');
        cout << setw(spaces) << "" << endl;
        if ((i += step) == (n+3)/2) break;
    }   
}

int main() {
    int foo;
    char bar;
    do 
    {
        cout << "Choose the shape to gragh \n"
             << "1 for sqaure\n"
             << "2 for diamond\n"
             << "3 for triangle.\n"
             << "?";
        cin >> foo;
        if (foo != 1 && foo !=2 && foo !=3) {
            cout << "Invalid choose, please retry.\n";
            continue;
        }
        cout << "Enter a character and size: ";
        int s;
        cin >> bar >> s;
        switch (foo) {
            case 1:
                square(s,bar);
                break;
            case 2:
                diamond(s,bar);
                break;
            case 3:
                triangle(s,bar);
                break;
            default:
                break;
        }
        cout << "Do you want to continue (y or n)?: ";
        cin >> bar;
    } while(bar == 'y');
    return 0;
}
